import { getRoleOption } from '@/api/sys/role';
import { getDepartmentOption } from '@/api/sys/department';
import { BasicColumn, FormSchema } from '@/components/Table';

export const columns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 80,
  },
  {
    title: '账号',
    dataIndex: 'account',
    width: 280,
  },
  {
    title: '用户头像',
    dataIndex: 'avatar',
    width: 120,
  },
  {
    title: '用户昵称',
    dataIndex: 'nick_name',
    width: 120,
  },
  {
    title: '手机号码',
    dataIndex: 'phone_desensitization',
    width: 150,
  },
  {
    title: '邮箱地址',
    dataIndex: 'email',
    width: 120,
  },
  {
    title: '所属部门',
    dataIndex: 'department_name',
    width: 100,
  },
  {
    title: '角色',
    dataIndex: 'role_name',
    width: 100,
  },
  {
    title: '最后一次登录ip地址',
    dataIndex: 'last_login_ip',
    width: 120,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 120,
  },
  {
    title: '个人简介',
    dataIndex: 'introduction',
    width: 120,
  },
  {
    title: '所在地',
    dataIndex: 'address',
    width: 120,
  },
  {
    title: '最后一次登录时间',
    dataIndex: 'last_login_at',
    width: 120,
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
  },
  // {
  //   title: '修改时间',
  //   dataIndex: 'updated_at',
  //   width: 120,
  // },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'account',
    label: '账号',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'phone',
    label: '手机号',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'nick_name',
    label: '昵称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'nick_name',
    label: '昵称',
    component: 'Input',
    required: true,
  },
  {
    field: 'phone',
    label: '手机号',
    component: 'Input',
    helpMessage: ['异步验证手机号是否重复'],
    rules: [
      {
        required: true,
        message: '请输入手机号码',
      },
    ],
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
    required: true,
  },
  {
    label: '角色',
    field: 'role',
    component: 'ApiSelect',
    componentProps: {
      api: getRoleOption,
      labelField: 'name',
      valueField: 'id',
    },
    defaultValue: 6,
    required: true,
  },
  {
    field: 'department',
    label: '所属部门',
    component: 'TreeSelect',
    componentProps: {
      api: getDepartmentOption,
      fieldNames: {
        label: 'title',
        value: 'id',
      },
    },
    required: true,
  },
  {
    label: '备注',
    field: 'introduction',
    component: 'InputTextArea',
  },
];
